package com.job.shuang.HomeWork0702;

import java.util.Scanner;

/**
 * @author Shuang
 * @version 1.0
 * @since 2022-07-02 21:12:37
 */
public class Game0702 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入玩游戏的人数:");
        int n=sc.nextInt();
        int victoryNumber = Game0702.getVictoryNumber(n);
        System.out.println("最后剩下："+victoryNumber);
    }
    //玩游戏 返回胜利的人数
    public static int getVictoryNumber(int n){
        int[] persons =new int[n];
        //为人们赋值
        for (int i = 0; i <persons.length ; i++) {
            persons[i]=i+1;
        }
        //玩游戏
        while (persons.length>3){
            //下一轮
            int[] newPersons = new  int[persons.length-1];
            for (int i = 3; i <persons.length ; i++) {
                newPersons[i-3] =persons[i];
            }
            newPersons[newPersons.length-2]=persons[0];
            newPersons[newPersons.length-1]=persons[1];
            //persons 换引用换地址为newPersons
        }
        return persons[1];
    }
}
